<?php
namespace Home\Controller;
use Think\Controller;
class VideoController extends Controller {
	

    public function index(){
    	$post=$_POST['data'];	
    	$data=json_decode($post,true);
		$uid=$data['uid'];
		$url=$data['url'];
		$val=array(
				"uid"=>$uid,
				"g1_value"=>$url,	
				"g1_score"=>100,
				"g1_created"=>date("Y-m-d H:i:s"),
				"g1_status"=>1,
				);
		$true=array("errcode"=>202,"errmsg"=>"ok");
		$para=array("errcode"=>401,"errmsg"=>"Lack of parameter ");
		$false=array("errcode"=>404,"errmsg"=>"The user does not exist");
		$win=array("errcode"=>405,"errmsg"=>"Add failure");
		
		if($uid!=""&&$url!=""){
		$re=M('user')->where('id='.$uid)->find();
			if($re){
				$res=M('score')->where('uid='.$uid)->find();
				if($res){			
					$up=M('score')->where("uid=".$uid)->data($val)->save();
				}else{	
					$up=M('score')->data($val)->add();
				}
				if($up){
					echo json_encode($true);exit;
				}else{
					echo json_encode($win);exit;
				}	
			}else{
			echo json_encode($false);exit;
			}
		}else{
		echo json_encode($para);exit;
		}
    }
	 

}
